
package com.huaweicloud.saaslanding.install.properties;

import static com.huaweicloud.saaslanding.install.constant.ModelConstant.LTS_PREFIX;

import com.huaweicloud.saaslanding.basic.utils.CheckNullUtil;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 功能描述
 *
 * @since 2022-08-08
 */
@EqualsAndHashCode
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@Validated
@ConfigurationProperties(prefix = LTS_PREFIX)
public class Lts {
    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 接入点 IP
     */
    private String ip;

    /**
     * 接入点 port
     */
    private int port;

    /**
     * LTS服务端点
     */
    private String endpoint;

    /**
     * 监听器类型
     */
    private String consumer;

    /**
     * 集群地址
     */
    private String bootstrapServers;

    /**
     * RocketMQ的生产者组名
     */
    private String producerGroup;

    public String getIp() {
        if (enabled && CheckNullUtil.isNotNull(ip)) {
            return ip;
        } else {
            throw new IllegalArgumentException("未启用lts或未配置ip名称");
        }
    }

    public int getPort() {
        if (enabled && CheckNullUtil.isNotNull(port)) {
            return port;
        } else {
            throw new IllegalArgumentException("未启用lts或未配置接入点port");
        }
    }
}
